{% extends 'html/base_template.html' %}

{% block top_script_section %}
    <script type="text/javascript">
        {% if status == Status.kInAuditing %}
            function confirm(id, ok) {
                if (ok) {
                    var formData = new FormData($("#id_form")[0]);
                    formData.append("id", id);
                    formData.append("flag", ok);
                    formData.append("level", {{ level }});
                    $.ajax({
                        url: "{{ urls.confirm }}",
                        type: "POST",
                        data: formData,
                        level: {{ level }},
                        processData: false,
                        contentType: false,
                        success: function (data) {
                            if (data.rltcode == 0) {
                                $('#example-1').dataTable()._fnAjaxUpdate();
                            } else {
                                alert(data.rltmsg)
                            }
                        },
                        error: function (data) {
                            alert(data);
                        }
                    });
                } else {
                    $("input[name='id']").attr('value', id)
                    $("#id_dialog_form").dialog("open");
                }
                return true;
            }
        {% endif %}

    </script>
{% endblock %}

{% block content_section %}
    <div id="id_dialog_form" title="请填写打回报告">
        <form>
            <fieldset>
                <div>
                    <input type="text" name="id" style="display: none">
                    <textarea style="margin: 20px;width: 520px;height: 230px;" id="id_result"
                              class="text ui-widget-content ui-corner-all" rows=""
                              cols=""></textarea>
                </div>
            </fieldset>
        </form>
    </div>
    <div class="panel panel-default">
        <div class="panel-heading">
            <h3 class="panel-title">{{ title }}</h3>
        </div>
        <div class="panel-body">
            <script type="text/javascript">
                jQuery(document).ready(function ($) {
                    $("#id_dialog_form").dialog({
                        autoOpen: false,
                        height: 400,
                        width: 600,
                        modal: true,
                        title: "",
                        buttons: {
                            "提交": function () {
                                $.post("{{ urls.confirm }}", {
                                    "id": $("input[name='id']").val(),
                                    "type": "confirm",
                                    "flag": 0,
                                    "level": {{ level }},
                                    "description": $("#id_result").val()
                                }, function (data) {
                                    if (data.rltcode == 0) {
                                        $('#example-1').dataTable()._fnAjaxUpdate();
                                    } else {
                                        $.modal.alert(data.rltmsg)
                                    }
                                });
                                $(this).dialog("close");
                            },
                            "取消": function () {
                                $(this).dialog("close");
                            }
                        }
                    });
                    $("#example-1").dataTable({
                        dom: "<'col-xs-9'<'col-xs-6'l><'col-xs-6'f>r>" +
                        "t" +
                        "<''<'col-xs-6'i><'col-xs-6'p>>",
                        aLengthMenu: [
                            [10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]
                        ],
                        bProcessing: true,
                        bPaginate: true,
                        fnDraw: false,
                        bLengthChange: true,
                        bStateSave: false,
                        bServerSide: true,
                        bDestroy: true,
                        sServerMethod: "POST",
                        sAjaxSource: "{{ urls.query }}",
                        fnServerParams: function (aoData) {
                            aoData.push({'name': 'status', 'value': {{ status }}});
                            aoData.push({'name': 'level', 'value': {{ level }}});
                        },
                        columns: [
                            {"data": "index"},
                            {"data": "name"},
                            {"data": "type"},
                            {"data": "stime"},
                            {
                                "render": function (obj) {
                                    return '新游戏';
                                }
                            },
                            {
                                "data": "id", "render": function (obj) {
                                return '<a href="{{ urls.check_game_info }}?id=' + obj + '" class="btn btn-info btn-sm btn-icon icon-left">查看</a>';
                            }
                            },
                            {% if status == Status.kInAuditing %}
                                {% if level == 1 %}
                                    {
                                        "data": "id", "render": function (obj) {
                                        name = "report" + obj;
                                        return '<input name="' + name + '" type="file"/>';
                                    }
                                    },
                                {% elif level == 2 %}
                                    {
                                        "data": "report", "render": function (obj) {
                                        return '<a href="' + obj + '" class="btn btn-secondary btn-sm btn-icon"><下载></下载></a>';
                                    }
                                    },
                                {% endif %}
                                {
                                    "data": "id", "render": function (obj) {
                                    return '<div><a  onclick="confirm(' + obj + ',' + 1 + ');' + '" class="btn btn-secondary btn-sm btn-icon">通过</a>' +
                                            '<a onclick="confirm(' + obj + ',' + 0 + ');' + '" class="btn btn-danger btn-sm btn-icon icon-left">打回</a></div>';
                                }
                                },
                            {% elif status == Status.kRejected %}
                                {
                                    "data": "description", "render": function (obj) {
                                    return '<a onclick="alert(\'' + obj + '\');" class="btn btn-secondary btn-sm btn-icon">查看</a>';
                                }
                                },
                            {% elif status == Status.kAccepted %}
                                {
                                    "render": function (data, type, full) {
                                        return "";
                                    }
                                },
                                {
                                    "render": function (data, type, full) {
                                        return '<div><a href="' + full.report + '" class="btn btn-secondary btn-sm btn-icon">下载报告</a>' +
                                                '<a class="btn btn-orange btn-sm btn-icon icon-left">撤回</a></div>';
                                    }
                                },
                            {% endif %}
                        ],
                        language: {
                            "sProcessing": "处理中...",
                            "sLengthMenu": "每页显示 _MENU_ 条结果",
                            "sZeroRecords": "没有匹配结果",
                            "info": "第 _PAGE_ 页 ( 总共 _PAGES_ 页 ,_TOTAL_条)",
                            "sInfoEmpty": "显示第 0 至 0 条结果，共 0 条",
                            "infoFiltered": "(从 _MAX_ 条记录过滤)",
                            "sInfoPostFix": "",
                            "sSearch": "模糊搜索:",
                            "sUrl": "",
                            "sEmptyTable": "表中数据为空",
                            "sLoadingRecords": "载入中...",
                            "sProcessing": "<img src='assets/images/loding.gif'/> 正在加载数据...",
                            "sInfoThousands": ",",
                            "oPaginate": {
                                "sFirst": "首页",
                                "sPrevious": "上页",
                                "sNext": "下页",
                                "sLast": "末页"
                            }
                        }
                    });


                });

            </script>
            <div class="col-xs-3 table_but">
                <a href="#">导出当页</a>
                <a href="#">选择导出</a>
                {#                <a href="#">批量通过</a>#}
            </div>
            <div class="dataTables_wrapper form-inline dt-bootstrap no-footer"
                 id="example-1_wrapper">
                {#                <div class="col-xs-9">#}
                {#                    <div class="col-xs-6">#}
                {#                        <div id="example-1_length" class="dataTables_length"><label>每页显示 <select#}
                {#                                class="form-control input-sm" aria-controls="example-1"#}
                {#                                name="example-1_length">#}
                {#                            <option value="10">10</option>#}
                {#                            <option value="25">25</option>#}
                {#                            <option value="50">50</option>#}
                {#                            <option value="100">100</option>#}
                {#                            <option value="-1">All</option>#}
                {#                        </select> 条结果</label></div>#}
                {#                    </div>#}
                {#                    <div class="col-xs-6">#}
                {#                        <div class="dataTables_filter" id="example-1_filter"><label>模糊搜索:<input#}
                {#                                aria-controls="example-1" placeholder=""#}
                {#                                class="form-control input-sm" type="search"></label></div>#}
                {#                    </div>#}
                {#                </div>#}

                <form enctype="multipart/form-data" id="id_form" method="post"
                      action="{{ confirm_url }}">
                    <table aria-describedby="example-1_info" role="grid"
                           class="table table-bordered table-striped dataTable no-footer"
                           id="example-1">

                        <thead>
                        <tr role="row">
                            <th aria-label=": activate to sort column ascending"
                                style="width: 31px;"
                                colspan="1" rowspan="1" aria-controls="example-1" tabindex="0"
                                class="sorting"></th>
                            <th aria-label="产品名称: activate to sort column ascending"
                                style="width: 96px;" colspan="1" rowspan="1"
                                aria-controls="example-1"
                                tabindex="0" class="sorting">产品名称
                            </th>
                            <th aria-label="类型: activate to sort column ascending"
                                style="width: 58px;"
                                colspan="1" rowspan="1" aria-controls="example-1" tabindex="0"
                                class="sorting">类型
                            </th>
                            <th aria-label="提交时间: activate to sort column ascending"
                                style="width: 158px;" colspan="1" rowspan="1"
                                aria-controls="example-1"
                                tabindex="0" class="sorting">提交时间
                            </th>
                            <th aria-label="提交类弄: activate to sort column ascending"
                                style="width: 96px;" colspan="1" rowspan="1"
                                aria-controls="example-1"
                                tabindex="0" class="sorting">提交类弄
                            </th>
                            <th aria-label="产品信息: activate to sort column ascending"
                                style="width: 96px;" colspan="1" rowspan="1"
                                aria-controls="example-1"
                                tabindex="0" class="sorting">产品信息
                            </th>
                            {% if status == Status.kInAuditing %}
                                <th aria-label="测评报告: activate to sort column ascending"
                                    style="width: 326px;" colspan="1" rowspan="1"
                                    aria-controls="example-1"
                                    tabindex="0" class="sorting">测评报告
                                </th>
                                <th aria-label="操作: activate to sort column ascending"
                                    style="width: 136px;"
                                    colspan="1" rowspan="1" aria-controls="example-1" tabindex="0"
                                    class="sorting">操作
                                </th>
                            {% elif status == Status.kRejected %}
                                <th aria-label="打回报告: activate to sort column ascending"
                                    style="width: 326px;" colspan="1" rowspan="1"
                                    aria-controls="example-1"
                                    tabindex="0" class="sorting">打回报告
                                </th>
                            {% elif status == Status.kAccepted %}
                                <th aria-label="测评报告: activate to sort column ascending"
                                    style="width: 326px;" colspan="1" rowspan="1"
                                    aria-controls="example-1"
                                    tabindex="0" class="sorting">测评报告
                                </th>
                                <th aria-label="操作: activate to sort column ascending"
                                    style="width: 136px;"
                                    colspan="1" rowspan="1" aria-controls="example-1" tabindex="0"
                                    class="sorting">操作
                                </th>
                            {% endif %}
                        </tr>
                        </thead>
                        <tbody class="middle-align">

                        </tbody>

                    </table>
                </form>

            </div>
        </div>
    </div>

{% endblock %}
